package com.sp.writer_;

import java.io.*;

/**
 * 文本复制功能
 */
public class BufferedCopy_ {
    public static void main(String[] args) {
        String srcFilePath = "d:\\development\\code\\IO_Test\\news\\story.txt";
        String destFilePath = "d:\\development\\code\\IO_Test\\news\\story1.txt";

        BufferedReader bufferedReader = null;
        BufferedWriter bufferedWriter = null;
        String line;


        try {
            bufferedReader = new BufferedReader(new FileReader(srcFilePath));
            bufferedWriter = new BufferedWriter(new FileWriter(destFilePath));

            //readLine 读取一行内容, 但是没有换行
            while ((line = bufferedReader.readLine()) != null) {
                //每读取一行, 就写入
                bufferedWriter.write(line);
                //插入一个换行
                bufferedWriter.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
                if (bufferedWriter != null) {
                    bufferedWriter.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }
}
